package com.xu.system.model.convert;

import com.xu.system.model.entity.SysMenu;
import com.xu.system.model.pojo.menu.AddMenuReq;
import com.xu.system.model.pojo.menu.MenuSimpleTreeVo;
import com.xu.system.model.pojo.menu.MenuTreeVo;
import com.xu.system.model.pojo.menu.MenuVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * 菜单对象转换器
 *
 * @Author: 许乾伟
 * @Date: 2024/12/9 9:37
 */
@Mapper(componentModel = "spring")
public interface MenuConvert {
    @Mappings({
            @Mapping(target = "createBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "createTime", expression = "java(java.time.LocalDateTime.now())"),
            @Mapping(target = "updateBy", expression = "java(com.xu.security.utils.SecurityUtils.getUserId())"),
            @Mapping(target = "updateTime", expression = "java(java.time.LocalDateTime.now())"),
    })
    SysMenu toSysMenu(AddMenuReq data);
    @Mappings({
            @Mapping(source = "id", target = "menuId")
    })
    MenuVo toMenuVo(SysMenu data);

    @Mappings({
            @Mapping(source = "id", target = "menuId")
    })
    MenuTreeVo toMenuTreeVo(SysMenu data);
    List<MenuTreeVo> toMenuTreeVoList(List<SysMenu> list);
    @Mappings({
            @Mapping(source = "id", target = "menuId")
    })
    MenuSimpleTreeVo toMenuSimpleTreeVo(SysMenu data);
    List<MenuSimpleTreeVo> toMenuSimpleTreeVoList(List<SysMenu> list);
}
